#!/bin/bash
# 课堂互动信号接收系统启动脚本

echo "========================================"
echo "      课堂互动信号接收系统启动器"
echo "========================================"

# 确保数据目录存在
if [ ! -d "data" ]; then
  echo "创建数据目录..."
  mkdir -p data
fi

# 检查Python是否安装
if ! command -v python3 &> /dev/null; then
  echo "错误: 未找到Python 3，请先安装Python 3.8或更高版本"
  exit 1
fi

# 检查依赖项
echo "检查依赖项..."
if ! python3 -c "import streamlit, bleak, numpy, pandas, matplotlib" 2>/dev/null; then
  echo "缺少依赖项，是否自动安装? (y/n)"
  read -r install
  if [ "$install" = "y" ] || [ "$install" = "Y" ]; then
    echo "安装依赖项..."
    python3 -m pip install -r requirements.txt
  else
    echo "请手动安装依赖项: pip install -r requirements.txt"
    exit 1
  fi
fi

# 启动应用
echo "启动课堂互动信号接收系统..."
python3 -m streamlit run app.py

# 如果程序异常终止，显示错误信息
if [ $? -ne 0 ]; then
  echo "程序异常终止，请检查控制台输出获取详细信息"
fi 